﻿using System;
using Aspects.PInvoke;

namespace Aspects.Unit
{
    class MemoryInformation
    {
        public static string GetTotalMemory()
        {
            var memory = new Native.MEMORYSTATUSEX();
            memory.Instantiate();

            Native.GlobalMemoryStatusEx(memory);

            return BytesToGigabytes(memory.ullTotalPhys);
            
        }
        private static string BytesToGigabytes(ulong bytes)
        {
            if (bytes == 0)
                return "0 GB";
            else
            {
                bytes /= 1000; //bytes > kilobytes
                bytes /= 1000; //kilobytes > megabytes
                bytes /= 1000; //megabytes > gigabytes
                return bytes + " GB";
            }
        }
    }
}
